unit SmallStruct.BusinessObject.TSSBusinessObject;

interface

uses Classes,
  SmallStruct.Core,
  SmallStruct.Core.TSSRuntimeObject,
  SmallStruct.Core.TSSObjectContainer,
  SmallStruct.Core.TSSObjectContext,
  SmallStruct.BusinessObject;

type
  TSSBusinessObjectContext = class(TSSObjectContext, ISSBusinessObjectContext)
  private
    _BusinessObjectContainer, _ModelContainer: TSSObjectContainer;
    _SystemObject: ISSSystemObject;
  public
    function GetBusinessObjectContainer: ISSObjectContainer;
    function GetModelContainer: ISSObjectContainer;
    function GetSystemObject: ISSSystemObject;
    procedure SetSystemObject(ASystemObject: ISSSystemObject);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

  TSSBusinessObject = class(TSSRuntimeObject, ISSBusinessObject)
  protected
    function QueryBO(const ABOName: string): ISSBusinessObject;
  end;

  TSSBusinessObjectClass = class of TSSBusinessObject;

implementation

{ TSSBusinessObjectContext }

constructor TSSBusinessObjectContext.Create(AOwner: TComponent);
begin
  inherited;
  _BusinessObjectContainer := TSSObjectContainer.Create(Self);
  _ModelContainer := TSSObjectContainer.Create(Self);
end;

destructor TSSBusinessObjectContext.Destroy;
begin
  _BusinessObjectContainer.ReleaseObject;
  _ModelContainer.RemoveObject;

  inherited;
end;

function TSSBusinessObjectContext.GetBusinessObjectContainer: ISSObjectContainer;
begin
  Result := _BusinessObjectContainer;
end;

function TSSBusinessObjectContext.GetModelContainer: ISSObjectContainer;
begin
  Result := _ModelContainer;
end;

function TSSBusinessObjectContext.GetSystemObject: ISSSystemObject;
begin
  Result := _SystemObject;
end;

procedure TSSBusinessObjectContext.SetSystemObject(ASystemObject: ISSSystemObject);
begin
  _SystemObject := ASystemObject;
end;

{ TSSBusinessObject }

function TSSBusinessObject.QueryBO(const ABOName: string): ISSBusinessObject;
begin
  Result := (GetContext as ISSBusinessObjectContext).GetBusinessObjectContainer.GetObject(ABOName) as ISSBusinessObject;
end;

end.
